def maxNonnegSliceSum ( A ):
    '''unittest
    >>> maxNonnegSliceSum([1, 2, -3, 4, 5, -6])
    9
    >>> maxNonnegSliceSum([-8, 3, 0, 5, -3, 4])
    8
    >>> maxNonnegSliceSum([-1, 1, 1, -1])
    2
    >>> maxNonnegSliceSum([-1])
    -1
    >>> maxNonnegSliceSum([])
    -1
    >>> maxNonnegSliceSum([0])
    0
    >>> maxNonnegSliceSum([0,0])
    0
    >>> maxNonnegSliceSum([1,1,1])
    3
    >>> maxNonnegSliceSum([-1,0])
    0
    '''
    if not len(A):
        return -1
    
    B = []
    sum = 0
    for i in xrange(len(A)):
        if A[i] >= 0:
            sum += A[i]
        else:
            if sum >= 0:
                B.append(sum)
            sum = 0
    
    B.append(sum) #for last sum
    
    if max(B):
        return max(B)
    else:
        if A[0] == 0 or A[-1] == 0:
            return 0
        else:
            return -1

import doctest
doctest.testmod()